package com.vector.demo.controller.admin;

import com.vector.demo.pojo.Student;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 管理员登录
 */
@Controller
@RequestMapping("/admin")
public class AdminLogin {
    /**
     * admin登录
     * @param username
     * @param pwd
     * @param session
     * @return
     */
    @ResponseBody
    @RequestMapping("/doLogin")
    public String doLogin(String username, String pwd, HttpSession session) {
        System.out.println(username+" "+pwd);
        if("admin".equals(username) && "root".equals(pwd)) {
            if(session.getAttribute("admin")==null){
                session.setAttribute("admin", "admin");
            }
            return "登录成功";
        }
        return "登录失败";
    }

    /**
     * 登录成功跳转页面
     * @param session
     * @return
     */
    @GetMapping("/Menu")
    public String Menu(HttpSession session) {
        return "admin_index";
    }



    /**
     * 退出 登录 Controller
     */
    @RequestMapping("/doLogout")
    public String doLogout(HttpSession session) {
        session.removeAttribute("admin");
        System.out.println(session.getAttribute("admin"));
        return "login";
    }


}
